using System;
using System.IO;
using Portal.API;
namespace Portal
{
	/// <summary>
	/// Startup Page. Redirects in dependents of the PortalType to the Pages "RenderTable.aspx" or "FrameSet.htm"
	/// </summary>
	public partial class StartPage : System.Web.UI.Page
	{
		protected void Page_Load(object sender, System.EventArgs e)
		{
			/*// Where do we come from?
			if(Config.LogUrlReferrer && Request.UrlReferrer != null)
			{
				StreamWriter sw = new StreamWriter(Server.MapPath("~/UrlReferrer.log.txt"), true);
				sw.WriteLine("{0};{1}", DateTime.Now.ToString(), Request.UrlReferrer);
				sw.Close();
			}*/

			// Check web.config for render method
			//if(Config.GetPortalType() == Config.PortalType.Table)
			//{
				// Find first Tab in Level 1
				PortalDefinition _objPD = PortalDefinition.Load();
				if (_objPD != null && _objPD.tabs != null && _objPD.tabs.Count > 0)
				{
                    ChannelUsers objUser = new ChannelUsers();
					foreach (PortalDefinition.Tab _objTab in _objPD.tabs)
					{
                        if (!_objTab.IsHidden && objUser.HasViewRights(Page.User, _objTab.roles))
						{
							string _strMainPage = Config.GetTabURL(_objTab.reference);
							Response.Redirect(_strMainPage);
							Response.End();
							break;
						}
					}
				}
				else
				{
					Response.Redirect( Config.GetMainPage(Page.User.Identity.Name));
				}
            //}
            //else
            //{
            //     Response.Redirect("FrameSet.htm");
            //}
		}

		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
		}
	}
}
